/**
 * 
 */
package com.goldentrail.neo4j;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Describes a relationship as used in path finding and traversals
 * @author mikeagun
 * 
 */
public class RelationshipSpec {
	private String type;
	private String direction;

	/** Constructor that specifies both relationship type and direction
	 * @param type  type of the relationship
	 * @param direction  direction of the relationship (which can be in,out, or all)
	 */
	public RelationshipSpec(String type, String direction) {
		this.type = type;
		this.direction = direction;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the direction
	 */
	public String getDirection() {
		return direction;
	}

	/**
	 * @param direction
	 *            the direction to set
	 */
	public void setDirection(String direction) {
		this.direction = direction;
	}

	/**
	 * Gets the JSONObject representing the relationship
	 * @return JSONObject representing relationship
	 */
	public JSONObject getJson() {
		try {
			JSONObject json = new JSONObject();
			if (type != null)
				json.put("type", type);
			if (direction != null)
				json.put("direction", direction);
			return json;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		JSONObject json = getJson();
		if (json == null)
			return null;
		return json.toString();
	}
}
